import React from 'react';
import { WeaInputNumber } from 'ecCom';
import { Icon } from 'antd';
import {WeaLocaleProvider} from 'ecCom';
import './../../style/newlinked/newLinkeb';
const getLabel = WeaLocaleProvider.getLabel;
const getUserLanguage= WeaLocaleProvider.getUserLanguage;
export default class NewLinkeb extends React.Component{
  constructor(props){
    super(props)
  }
  render(){
    const {linkdatas,linkurl,hasdel,_width,replaceData,hasdownload} = this.props;
    return(
       <div className={"wea-workrelate-newlinkeds "+(this.props.className?this.props.className:"")}>
          {
            this.createLinked(linkdatas,linkurl,hasdel,_width,replaceData,hasdownload)
          }
       </div>
    )
  }
  createLinked(linkdatas,linkurl,hasdel,_width,replaceData,hasdownload){
    let pright = "5px";
    // if(hasdownload){
    //   if(getUserLanguage()==8){
    //     pright = "110px";
    //   }else{
    //     pright = "80px";
    //   }
    // }else
    if(hasdel){
      pright = "25px";
    }
    return (
      linkdatas && linkdatas.length > 0 && linkdatas.map((element,idx)=>{
        return (
          element.name?<div className="wea-workrelate-link">
              <div className="wea-workrelate-link-item" style={{width:_width?_width:"auto",paddingRight:pright}}>
                 {element.icon?<Icon ecId={`${this && this.props && this.props.ecId || ''}_Icon@3jmses@${element.id}`} type={element.icon} style={{paddingRight: "5px"}}/>:""}
                 {linkurl?<a href={replaceData?linkurl.replace(replaceData,element.id):linkurl+element.id} target="_blank" className="wea-workrelate-link-item-a" title={element.name}>{element.name}</a>:
                          <span className="wea-workrelate-link-item-name" onClick={(e)=>this.onLinkClick(element.id,element.name,1,e)} title={element.name}>{element.name}</span>}
                 {hasdel?<div className="wea-workrelate-link-item-del" title={getLabel(91,"删除")} onClick={(e)=>this.onLinkClick(element.id,element.name,2,e)}><Icon ecId={`${this && this.props && this.props.ecId || ''}_Icon@adrggi@${element.id}`} type="cross"/></div>:""}
                 {hasdownload?<span className="wea-workrelate-link-item-down" onClick={(e)=>this.onLinkClick(element.id,element.name,3,e,element.fileid)} title={getLabel(258,"下载")}>{getLabel(258,"下载")}{element.size?"("+element.size+")":""}</span>:""}
              </div>
            </div>:""
        )
      })
    )
  }
  //type 1-浏览 2-删除 3-下载
  onLinkClick(id,name,type,e,fileid){
    if(typeof this.props.onLinkClick === "function"){
      this.props.onLinkClick(id,name,type,fileid);
    }else{
      console.log(id+"=="+name+"=="+type);
    }
    e.stopPropagation();
    e.nativeEvent.stopImmediatePropagation();
  }
}